home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-06-01 | 3.4 KB | 107 lines | [ftFC/NLft] |
- {
- This function allows you to easily fit multiple Gaussian peaks.
-
- To compile the function, click the button "Add" above.
-
- To start a fit, first display your data in the preview window.
- Also make sure that the function 'Peaks' is displayed in the
- parameter window: choose Peaks from the Func menu, then check
- "Show function" in the preview.
-
- Now, you should set the parameters 'const' and 'm' of the
- function. These parameters describe the background of your
- data. You must set these parameters such that the function
- approximately goes through the lowermost data points of your
- data set.
- To do this, you preferably use the Fit tool of the preview window.
-
- Then you choose the Marker tool of the preview window and set a
- marker on top of each peak you see in your data. Once this is
- done, click the button "Read Markers" in the parameters window.
- This sets the position and amplitude of all gaussian peaks.
-
- In a next step, set the parameters k1, k2, etc. such that each
- peak has approximately the correct width. You again can use
- the Fitting tool in the parameter window for this work.
-
- Finally, choose "Nonlinear Fit..." from the Calc menu to run the
- fit.
-
-
- This example shows how to use the markers in the preview window
- from a function/program. It also shows how to bring up a button
- in the Parameters window.
- }
-
- function Peaks;
-
- defaults
- a[1] := 3,constant,'#peaks',0,9;
- a[2] := 0,active,'const';
- a[3] := 0,active,'m';
-
- a[4] := 0,active,'x1'; a[5] := 1,active,'A1'; a[6] := 1,active,'k1';
- a[7] := 5,active,'x2'; a[8] := 1,active,'A2'; a[9] := 1,active,'k2';
- a[10] := 10,active,'x3'; a[11] := 1,active,'A3'; a[12] := 1,active,'k3';
- a[13] := 15,active,'x4'; a[14] := 1,active,'A4'; a[15] := 1,active,'k4';
- a[16] := 20,active,'x5'; a[17] := 1,active,'A5'; a[18] := 1,active,'k5';
- a[19] := 25,active,'x6'; a[20] := 1,active,'A6'; a[21] := 1,active,'k6';
- a[22] := 30,active,'x7'; a[23] := 1,active,'A7'; a[24] := 1,active,'k7';
- a[25] := 35,active,'x8'; a[26] := 1,active,'A8'; a[27] := 1,active,'k8';
- a[28] := 40,active,'x9'; a[29] := 1,active,'A9'; a[30] := 1,active,'k9';
-
- description
- 'Multiple Gaussian peaks. #peaks = number of peaks.',
- '$BRead Markers...$ y := SUM(Ai*exp(-ki*(x-xi)^2)) + const';
- {note that the second string starts with $B...$, which indicates
- that there should be a button in the Parameters window}
- var
- i:integer;
-
- procedure Check;
- var xm, ym,i,max;
- begin
- if pNumber = 30000 then {if button clicked, pNumber is always 30000}
- begin
- max := 0;
- for i := 0 to 8 do
- begin
- GetMarkedCoord(i,xm,ym);
- if not (Invalid(xm) or Invalid(ym)) then
- begin
- SetParamDefaultValue(3*i+4, xm);
- SetParamDefaultValue(3*i+5, ym-a[2]-a[3]*xm);
- max := i+1;
- end
- else
- SetParamDefaultValue(3*i+5, 0);
- end;
- SetParamDefaultValue(1, max);
- check := update;
- end
- else if pNumber = 1 then
- begin
- for i := 0 to 8 do
- if a[1] > i then
- begin
- if mode[3*i+3] = constant then mode[3*i+4] := active;
- if mode[3*i+4] = constant then mode[3*i+5] := active;
- if mode[3*i+5] = constant then mode[3*i+6] := active;
- end
- else
- begin
- mode[3*i+4] := constant;
- mode[3*i+5] := constant;
- mode[3*i+6] := constant;
- end;
- check := update;
- end
- else check := ok;
- end;
-
- begin
- y := a[2] + a[3]*x;
- for i := 1 to a[1] do
- y := y + a[3*i+2]*exp(-a[3*i+3]*sqr(x-a[3*i+1]));
- end;
-